package com.spc.car.data.service.base.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spc.car.data.entity.base.BaseArea;
import com.spc.car.data.mapper.base.BaseAreaMapper;
import com.spc.car.data.service.base.BaseAreaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 区域代码表 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-03-23
 */
@Service
public class BaseAreaServiceImpl extends ServiceImpl<BaseAreaMapper, BaseArea> implements BaseAreaService {

    @Override
    public List<BaseArea> listArea(BaseArea baseArea) {

        return list(new LambdaQueryWrapper<BaseArea>()
                .eq(BaseArea::getLevel, 1)
                .like(StringUtils.isNotBlank(baseArea.getName()), BaseArea::getName, baseArea.getName()));
    }

    @Override
    public List<BaseArea> listAreaByParent(@NotNull Long pid) {
        return list(new LambdaQueryWrapper<BaseArea>().eq(BaseArea::getParentCode, pid));
    }
}
